package com.gitee.minimalismstyle.fresh.simple.service.impl

import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.common.core.domain.Simple
import com.gitee.minimalismstyle.fresh.common.core.option.Options
import com.gitee.minimalismstyle.fresh.common.core.spring.SpringContextUtils
import com.gitee.minimalismstyle.fresh.simple.api.service.OptionService
import org.springframework.context.annotation.Primary
import org.springframework.stereotype.Service

@Service
@Primary
class OptionServiceImpl : OptionService {
    override fun findMapByType(type: String, param: String): R<Map<String, Simple>> {
        val map = linkedMapOf<String, Simple>()
        val options: Options = SpringContextUtils.getBean("${type}Options")
        options.get(param).forEach {
            map[it.getString("key", "")] = it
        }
        return R.success(map)
    }

    override fun findByType(type: String, param: String): R<List<Simple>> {
        val options: Options = SpringContextUtils.getBean("${type}Options")
        return R.success(options.get(param))
    }

}